﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;



namespace syc.ZhiJian
{
    public partial class 产品理化参数修改 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           // sql = @"SELECT [ID],[炉号], [C], [Mn], [Si], [P], [S], [Cr], [Ni], [Cu], [Mo], [Al], [V], [Bi], [Sn], [Pb], [As], [Sb], [抗拉强度], [屈服极限], [伸长率] FROM [产品理化参数] where 产品ID=" + Request.QueryString["type"];
            this.Message.Text = "·准备就绪";
            if (!this.IsPostBack)
            {
                ruku_proess();
            }
           
        }
         //private string sql;

        //处理有传入入库单ID参数的子函数
         protected void ruku_proess()
         {
             string rukuid = Request.QueryString["id"];
           
             //如果有传送入库单参数则
             if (rukuid != null)
             {
                 SqlConnection Conn = new SqlConnection();
                 Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
                 SqlDataAdapter sda = new SqlDataAdapter("Select * From 产品理化参数 where ID="+Request.QueryString["id"], Conn);
                 DataSet ds = new DataSet();
                 sda.Fill(ds);
                 //如果取得炉号所对应的值则
                 if (ds.Tables[0].Rows.Count != 0)
                 {

                     LuHao0.Text = ds.Tables[0].Rows[0][2].ToString();
                     C.Text = ds.Tables[0].Rows[0][3].ToString();
                     Mn.Text = ds.Tables[0].Rows[0][4].ToString();
                     Si.Text = ds.Tables[0].Rows[0][5].ToString();
                     P.Text = ds.Tables[0].Rows[0][6].ToString();
                     S.Text = ds.Tables[0].Rows[0][7].ToString();
                     Cr.Text = ds.Tables[0].Rows[0][8].ToString();
                     Ni.Text = ds.Tables[0].Rows[0][9].ToString();
                     Cu.Text = ds.Tables[0].Rows[0][10].ToString();
                     Mo.Text = ds.Tables[0].Rows[0][11].ToString();
                     Al.Text = ds.Tables[0].Rows[0][12].ToString();
                     V.Text = ds.Tables[0].Rows[0][13].ToString();
                     Bi.Text = ds.Tables[0].Rows[0][14].ToString();
                     Sn.Text = ds.Tables[0].Rows[0][15].ToString();
                     Pb.Text = ds.Tables[0].Rows[0][16].ToString();
                     As.Text = ds.Tables[0].Rows[0][17].ToString();
                     Sb.Text = ds.Tables[0].Rows[0][18].ToString();
                     klqd.Text = ds.Tables[0].Rows[0][19].ToString();
                     qsjx.Text = ds.Tables[0].Rows[0][20].ToString();
                     scl.Text = ds.Tables[0].Rows[0][21].ToString();

                 }
                 //如果没有取到任何炉号信息则
                 else
                 {

                     C.Text = "";
                     Mn.Text = "";
                     Si.Text = "";
                     P.Text = "";
                     S.Text = "";
                     Cr.Text = "";
                     Ni.Text = "";
                     Cu.Text = "";
                     Mo.Text = "";
                     Al.Text = "";
                     V.Text = "";
                     Bi.Text = "";
                     Sn.Text = "";
                     Pb.Text = "";
                     As.Text = "";
                     Sb.Text = "";
                     klqd.Text = "";
                     qsjx.Text = "";
                     scl.Text = "";
                 }
             }
            
         }
        protected void Button_Save_Click(object sender, EventArgs e)
        {
            try
            {
               
                SqlConnection Conn = new SqlConnection();
                Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
                Conn.Open();

                SqlCommand Cmd = new SqlCommand();
                Cmd.Connection = Conn;

                Cmd.CommandText = @"update [产品理化参数]set C=@C,Mn=@Mn,Si=@Si,P=@P,S=@Si,Cr=@Cr,Ni=@Ni,Cu=@Cu,
Mo=@Mo,Al=@Al,V=@V,Bi=@Bi,Sn=@Sn,Pb=@Pb,[As]=@As,Sb=@Sb,抗拉强度=@抗拉强度,
屈服极限=@屈服极限,伸长率=@伸长率 where ID=@ID";               
                Cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, Request.QueryString["id"]));
                Cmd.Parameters.Add(new SqlParameter("@炉号", SqlDbType.NVarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.LuHao0.Text));
                Cmd.Parameters.Add(new SqlParameter("@C", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.C.Text));
                Cmd.Parameters.Add(new SqlParameter("@Mn", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Mn.Text));                
                Cmd.Parameters.Add(new SqlParameter("@Si", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Si.Text));
                Cmd.Parameters.Add(new SqlParameter("@P", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.P.Text));
                Cmd.Parameters.Add(new SqlParameter("@Cr", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Cr.Text));
                Cmd.Parameters.Add(new SqlParameter("@Ni", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Ni.Text));
                Cmd.Parameters.Add(new SqlParameter("@Cu", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Cu.Text));
                Cmd.Parameters.Add(new SqlParameter("@Mo", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Mo.Text));
                Cmd.Parameters.Add(new SqlParameter("@Al", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Al.Text));
                Cmd.Parameters.Add(new SqlParameter("@V",  SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.V.Text));
                Cmd.Parameters.Add(new SqlParameter("@Bi", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Bi.Text));
                Cmd.Parameters.Add(new SqlParameter("@Sn", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Sn.Text));
                Cmd.Parameters.Add(new SqlParameter("@Pb", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Pb.Text));
                Cmd.Parameters.Add(new SqlParameter("@As", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.As.Text));
                Cmd.Parameters.Add(new SqlParameter("@Sb", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.Sb.Text));
                Cmd.Parameters.Add(new SqlParameter("@抗拉强度", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.klqd.Text));
                Cmd.Parameters.Add(new SqlParameter("@屈服极限", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.qsjx.Text));
                Cmd.Parameters.Add(new SqlParameter("@伸长率", SqlDbType.NVarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, this.scl.Text));

                Cmd.ExecuteNonQuery();               

                this.Message.Text = ".操作成功！";
            }
            catch (Exception ex)
            {
                this.Message.Text = ex.Message;
            }
        }
                
    }
}
